﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Radiation___IM.ApiCommands
{
    public class ChannelJoinOrCreate : ICommand
    {
        private readonly string m_commandkey = "channels.join_or_create";

        public ChannelJoinOrCreate()
        {
        }

        public string commandKey()
        {
            return m_commandkey;
        }

        public string requiredPermission()
        {
            return "create_channel";
        }

        public void execute(string[] commands, Client client)
        {
            if (commands.Length >= 3 &&
                commands[2].Length > 2)
            {
                if (ChannelManager.Instance[commands[2]] == null)
                {
                    ChannelManager.Instance.add(commands[2]);
                    ChannelManager.Instance[commands[2]].registerClient(client, true);
                    ChannelManager.Instance[commands[2]].dispatchMessageSystem(client.Nickname + " has created this channel");
                    ChannelManager.Instance[commands[2]].sendMotd(client);
                }
                else
                    ChannelManager.Instance[commands[2]].registerClient(client);
            }
        }
    }
}
